/* 
 *  Incub - incubate your baby robot
 *  Copyright (C) 2008 Stanislaw Szymczyk
 *  e-mail: sszymczy@gmail.com   www: http://cogville.cog-lab.com
 *
 *  This file is part of Incub.
 *
 *  Incub is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Incub is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Incub.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
 
#include "Vector3D.h"

Vector3D::Vector3D() {
	this->x = 0;
	this->y = 0;
	this->z = 0;
}

Vector3D::Vector3D(double x, double y, double z) {
	this->x = x;
	this->y = y;
	this->z = z;
}

Vector3D Vector3D::operator*(double s) {
	return Vector3D(x * s, y * s, z * s);
}

Vector3D Vector3D::operator+(Vector3D& v) {
	return Vector3D(x + v.x, y + v.y, z + v.z);
}

Vector3D Vector3D::operator-(Vector3D& v) {
	return Vector3D(x - v.x, y - v.y, z - v.z);
}

Vector3D Vector3D::operator-() {
	return Vector3D(-x, -y, -z);
}

void Vector3D::operator*=(double s) {
	x *= s;
	y *= s;
	z *= s;
}

double Vector3D::operator*(Vector3D& v) {
	return x*v.x + y*v.y + z*v.z;
}

double Vector3D::norm() {
	return sqrt(x * x + y * y + z * z);
}

Vector3D& Vector3D::normalize() { 
	operator*=(1.0/norm()); return *this; 
}

std::ostream& operator <<(std::ostream &os,const Vector3D &obj) {
      os << "[" << obj.x << ", " << obj.y << ", " << obj.z << "]";
      return os;
}
